<template>
  <div>
        <title-name title="资质证书"></title-name>
      <a-row>
        <button @click="addList">新增</button>
      </a-row>
    <a-table :data-source="tableData" :columns = "columns"></a-table>    
    <a-modal
            title="新增资质证书"
            :visible="visible"
            :confirm-loading="confirmLoading"
            width="1000px"
            @ok="handleOk"
            @cancel="handleCancel">
      <a-form>
        <a-row>
          <a-col :md="12" :sm="12">
            <a-form-model-item
                    label="资质类别"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="formAdd.certType" :disabled="type=='view'"  placeholder="请输入" />
            </a-form-model-item>
          </a-col>
          
          <a-col
                  :md="12" :sm="12">
            <a-form-model-item
                    label="资质证书编号"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="formAdd.certNum" :disabled="type=='view'"  placeholder="请输入" />
              <!-- <a-date-picker v-model="formAdd.time" :disabled="type=='view'" @change="changeTimes"></a-date-picker> -->
            </a-form-model-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-model-item
                    label="资质等级及承揽项目范围"
                    :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
                    :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
              <BaseInput v-model="formAdd.certLevelScope" :disabled="type=='view'" placeholder="请输入" />
              <!-- <a-select v-model="formAdd.certLevelScope">
                <a-select-option v-for="item in resList" :key="item.id">{{item.name}}</a-select-option>
              </a-select> -->
            </a-form-model-item>
          </a-col>
        
        </a-row>
      </a-form>
    </a-modal>
    <button @click="save"> 保存</button>
  </div>
</template>

<script>
import { getCompanyType  } from '@/api/design/resourceRecommend/basic'
import { addQualiyList ,editQualiyList , deleteQualiyList, getQualiyList} from '@/api/design/resourceRecommend/designCompany'
  import { getExpertList , editExpertList ,getCompanyDetails} from '@/api/design/resourceRecommend/basic'
  import { getTypesLabel } from '@/api/commons'
const columns=[
    {
      title: '序号',
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '资质类别',
      dataIndex: 'certType'
    },
    {
      title: '资质证书编号',
      dataIndex: 'certNum'
    },
    {
      title: '资质等级及承揽项目范围',
      dataIndex: 'certLevelScope'
    },
    {
      title: '操作',
      dataIndex: 'action',
      width: '150px',
      scopedSlots: { customRender: 'action' }
    }
]
export default {
  name:'a'+ Date.now(),
    data(){
      this.columns = columns
      return{
        companyType:'',
        dataSource:[],
        form:{},
        id:'',
        typeList:[],
        visible:false,
        formAdd:{},
        tableData:[]
        
      }
    },
    created(){
      this.id = this.$route.query.id
      // this.getQualiyList()
      this.getTypesLabel()
      this.getCompanyDetails()
    },
    methods:{
      // getCompanyType(){
      //   getCompanyType.then((res)=>{
      //     this.companyType = res.data
      //   })
      // },
      changeTime(value,dateString){
        this.form.registrationDate = dateString
      },
      getCompanyDetails(){
        if(this.id){
          getCompanyDetails({id:this.id}).then(res=>{
            this.form = res.data
            this.form.tableData = res.data.certifications
          })
        }
      },
      addList(){
        this.visible = true
        this.formAdd = {}
      },
      save(){
        this.tableData.forEach(item=>{
          item.id = null
        })
        this.form.certifications = this.tableData
        this.form.reCommandId = this.id
        this.form.auditStatus="0"
        editExpertList(this.form).then(res=>{

        })
      },
      changeCompanyType(){

      },
      handleOk(){
        this.visible = false
        if(this.id){
          if(this.formAdd.id){

          }else{
            let i=5
            this.formAdd.id = i++
            this.tableData.push(this.formAdd)
          }
        }else{
          if(this.formAdd.id){

          }else{
            let i=5
            this.formAdd.id = i++
            this.tableData.push(this.formAdd)
          }
        }
      },
      handleCancel(){
        this.visible = false
      },
      getTypesLabel(){
        // 企业性质
        getTypesLabel({type:'17'}).then(res=>{
          this.typeList = res.data
        })
      },
      // getQualiyList(){
      //   getQualiyList.then((res)=>{
      //     this.dataSource = res.data
      //   })
      // }
    }
}
</script>

<style>

</style>